﻿/*
创建人：zhangrj
日期：2022-10-10
描述：质量提起审核js
*/
var page = {
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ContainerQualityCollectHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
    },
    //页面事件绑定
    bind: function () {
        //质量问题处置单信息
        $('#QualityTabel').datagrid({
            rownumbers: true,
            columns: [[
                    { field: 'QUALITYHISTORYRECORDID', width: 100, checkbox: true },
                    { field: 'DEALNAME', title: '处置单号', width: 120 },
		            { field: 'MFGORDERNAME', title: '订单号', width: 100},
                    { field: 'PRODUCTITEMNAME', title: '件号', width: 100 },
                    { field: 'CONTAINERNO', title: '批次号', width: 80 },
                    { field: 'WORKFLOWSTEPNAME', title: '工序名称', width: 150 },
                    { field: 'STATUS', title: '处置单状态', width: 80 },
                    { field: 'UNQUALIFIEDNUM', title: '不合格品数', width: 70 },
                    { field: 'CHECKNO', title: '检验编号', width: 80 },
                    { field: 'PARTCATEGORY', title: '零件类别', width: 80 },
                    { field: 'DUTYNAME', title: '责任者', width: 60 },
                    { field: 'FACTORYNAME', title: '责任单位', width: 100 },
                    { field: 'UNQUALIFIEDDESCRIBE', title: '不合格描述', width: 150 },
                    { field: 'CREATENAME', title: '创建人', width: 60 },
                    { field: 'CREATETIME', title: '创建时间', width: 80,  },
                    { field: 'CONFIRMNAME', title: '处理人', width: 60 },
                    { field: 'CONFIRMDATE', title: '处理时间', width: 80 }
                ]]
        });
        //状态下拉事件
        $('#selStatus').combobox({
           onSelect:function(record){
             if (record.value==="1") {
                $("#btnExamine").linkbutton('disable');
             }else
             {
                $("#btnExamine").linkbutton('enable');
             }
           }
        });
    },
    //查询按钮
    searchData: function () {
        page.reset('', '');
        page.GetQualityQuestionExamine();
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        page.bind();
        page.reset('', '');
    },
    //查询
    GetQualityQuestionExamine: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetQualityCollectExamine",
            data: JSON.stringify([data])
        };
        page.post(page.ajaxUrl,param,true, function (res) {
        if (!res.Result) {
     displayMessage2(res.Message, false); 
           return;
}
            $('#QualityTabel').datagrid('loadData', res.DBTable);
        });
    },
    //审核
    QualityQuestionDealExamine: function () {
       $('#btnExamine').linkbutton('disable'); //禁用按钮
        var rows = $('#QualityTabel').datagrid("getChecked");
        if (rows.length == 0) 
        { 
           displayMessage2("请选择记录再进行操作", false,["btnExamine"]); 
           return; 
        }
        var qualityIDs = "";
        $.each(rows, function (index, item) {
            qualityIDs += "'" +item.QUALITYHISTORYRECORDID+"',";
        });
        var param = {
            action: "SaveQualityCollectExamine",
            qualityIDs: qualityIDs
        };
        page.post(page.ajaxUrl,param,true, function (res) {
            if (res.Result) {
                page.GetQualityQuestionExamine();
            }
            displayMessage2(res.Message, res.Result,["btnExamine"]);
        });

    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据（路径，参数，是否异步，成功返回方法）
    post: function (url, param, async, callback) {
        $.ajax({
            type: "Post",
            url: url,
            data: param,
            cashe: false,
            async: async,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
                $("body").find(".easyui-linkbutton").each(function () {
                    $(this).linkbutton('enable');
                });
            }
        });
    }
}
$(function () {
    page.init();
});